This page last changed on Oct 23, 2006 by cholmes.

This is some info on the STRUTS configuration web-app inside geoserver.

We'll look at a few example pages to get an idea about whats happening. I highly recommend that you get a book on STRUTs (the "free" on-line documentation isnt that great).

NOTE: The STRUTs code was written by people who didnt know STRUTs, so its not a good example of STRUTs programming. So, if you get confused or lost ITS NOT YOUR FAULT.

STRUTs is basically just a Model-View-Controller.

Model - This Java code that deals with getting and setting the Geoserver configuration details.
View - Mostly .JSPs that take a bean and make an HTML page. Note that there are also tiles (basically all the header/foot stuff for your HTML page) defined in the tiles-defs.xml file.
Controller - This is STRUTs and is mostly contained in struts-config.xml file. It basically connect goether the HTTP requests, model, forms, and .JSPs.

In a nutshell, this is what happens when you go to a xyz.do page:

1. your web container will recognize the "*.do" URL and pass your request off to STRUTs.
2. STRUTs will look up the settings for this request in the struts-config.xml files. The mapping will basically lay out the following steps:

  • create or reuse a Form object of the correct type (ie. see "<form-bean>" in the config)
  • this Form (Java object) will typically be very similiar to a bean that mimics the HTTP request (ie. GET and POST parameters) OR it may just dig up some information from the Geoserver configuration. Typically the Form is fairly simple.
  • the Form is then sent to the "main model (Java) class". This is typically where anything of interest is done. Usually this will update the configuration or do actual work.
  • the results of the main model class will be two things. (a) A Bean object and (b) a String "tag" that tells STRUTs where to go next.
  • based on the returned "tag", the Bean will typically be sent to either a JSP or tile definition for conversion to HTML.

The actual process is somewhat more difficult complex, and there's different modes etc...

A simple example will help to clear this up. Get Geoserver running and go to config->data->style. This will be the http://localhost:8080/geoserver/config/data/style.do page.


In this picture most of page is actually just generated from the tiles definition so each page looks exactly the same. The important portion of this page is highlighted - its a simple drop-down box that contains the list Geoserver's Styles and three buttons. One to 'edit' the style, one to 'delete' the style, and one to make the style the 'default' style.

This is a pretty simple page - lets look how STRUTs is used to make this page. We'll start off looking at the struts-config.xml file. In this you'll see the following:

... in global forwards ..
<forward
       	name="config.data.style"
       	path="/config/data/style.do"/>
... in the action mappings ...
 <action
        path="/config/data/style"
        type="org.apache.struts.actions.ForwardAction"
        parameter="config.data.style"/>
...

Inside the tiles-config.xml you'll see:

...
<!-- styles -->
<definition name="config.data.style" extends=".mainLayout">
	<put name="key" value="config.data.style"/>
	<put name="body" value="/WEB-INF/pages/data/styles/Select.jsp"/>
	<put name="status" value="/WEB-INF/pages/data/status.jsp"/>
	<put name="layer" value="data"/>
        <put name="locationForwards" value="welcome:config:config.data"/>
	<put name="configActions" value="/WEB-INF/pages/configActions.jsp"/>
        <put name="menuForwards" value="config.data.style.new"/>
</definition>
...

At this point you're probably confused. This is because the original developers used "config.data.style", "/config/data/style", and "/config/data/style.do" in a way that really makes it impossible to understand whats going on.

Also, there's indirect linkages in the .jsps. For example, a <html:form ...> element in Select.jsp will actually go and grab a Form object because the html form's action points to a .do (and therefore struts knows more about it).


style_do.gif (image/gif)
Document generated by Confluence on Jan 16, 2008 23:26